package com.gmail.shazi199.satoriex.entity.impl;

import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;

import com.gmail.shazi199.satoriex.App;
import com.gmail.shazi199.satoriex.entity.Collision;
import com.gmail.shazi199.satoriex.move.BasicBossMovement;
import com.gmail.shazi199.satoriex.move.Movement;
import com.gmail.shazi199.satoriex.utils.Coordinate;
import com.gmail.shazi199.satoriex.utils.Drawer;

public class Satori extends Enemy {

    private static final Log LOGGER = LogFactory.getLog(Satori.class);

    private Texture textureLeft;

    private double posX = Coordinate.MAX_STAGE_WIDTH / 2;
    private double posY = Coordinate.MAX_STAGE_HEIGHT / 3;

    private int frame = 0;

    private int gameTime = 0;

    private Movement movement;

    public Satori() {
        try {
            textureLeft = TextureLoader.getTexture("PNG", App.class.getResourceAsStream("resource/image/SatoriLeft.png"));
        } catch (IOException e) {
            LOGGER.error("Load Texture error.", e);
            App.getApp().exit();
        }
    }

    @Override
    public void draw() {
        Drawer.draw(textureLeft, (int) Coordinate.getDrawX(posX) - 24, (int) Coordinate.getDrawY(posY) - 32, 48, 64, (frame % 4) * 48, (frame / 4) * 64);
    }

    @Override
    public double getX() {
        return posX;
    }

    @Override
    public double getY() {
        return posY;
    }

    @Override
    public double getRadius() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public void getHurt(Collision other) {
        // TODO Auto-generated method stub

    }

    @Override
    public void update() {
        gameTime = (gameTime + 1) % 60;
        if (gameTime % 6 == 1) {
            frame = (frame + 1) % 8;
        }
        if (movement == null || movement.isEnded()) {
            Player p = App.getApp().getStage().getPlayer();
            if (p != null) {
                movement = new BasicBossMovement(this.posX, this.posY, p.getX(), p.getY());
            }
        }
        if (movement != null) {
            double[] position = movement.getNextPosition();
            this.posX = position[0];
            this.posY = position[1];
        }
    }

}
